import org.junit.Test;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * User: 5
 * Date: 16-12-19
 */
public class ThreadPools {

    @Test
    public void testExecutors() {
        ExecutorService executor = Executors.newCachedThreadPool();
        Future<?> sum = executor.submit(new Callable<Integer>() {


            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for (int i = 0; i < 100; i++) {
                    sum += i;
                }
                return sum;
            }
        });

        try {
            System.out.println(sum.get());
        } catch (InterruptedException e) {


        } catch (ExecutionException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

    }
}
